|
|
|
|
|
|
|
As String. So is lpszRemoteName, except that, since this string will contain the return value, you have to be sure to preinitialize it to the correct length. |
|
|
|
|
|
|
|
|
The lpnLength parameter is a pointer to a Long variable that contains the buffer length. Since the function expects a pointer, the parameter is passed by reference. |
|
|
|
|
|
|
|
|
The sample program starts out by calling the function with an empty string and the buffer length set to 0. This allows Windows to set the correct buffer length to use on the second call. |
|
|
|
|
|
|
|
|
The MapInfo1.vbp project contains the following code for the MapInfo1.frm file: |
|
|
|
|
|
|
|
|
' MapInfo1.vbp
' Copyright © 1998 by Desaware Inc. All Rights Reserved
Option Explicit
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _
lpszRemoteName As String, cbRemoteName As Long) As Long
Private Const ERROR_MORE_DATA = 234 ' dderror
' Get the source for a mapped drive
Private Function GetMappedInfo(ByVal Drive As String) As String
Dim Buffer As String
Dim BufferLength As Long
Dim res As Long
Drive = Left$(Drive, 2)
res = WNetGetConnection(Drive, Buffer, BufferLength)
If res = ERROR_MORE_DATA Then
Buffer = String$(BufferLength, 0)
res = WNetGetConnection(Drive, Buffer, BufferLength)
End If
If res <> 0 Then
lblSource.Caption = GetErrorString(Err.LastDllError)
Else
' Strip off the null termination character
lblSource.Caption = Left$(Buffer, BufferLength - 1)
GetMappedInfo = lblSource.Caption
End If
End Function |
|
|
|
|
|